package com.qc.blogsystemplus.controller.admin;

import com.qc.blogsystemplus.bean.ResponseBean;
import com.qc.blogsystemplus.entity.Article;
import com.qc.blogsystemplus.service.ArticleService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdArticleController {

    @Autowired
    private ArticleService articleService;

    @RequiresRoles("admin")
    @GetMapping("/getallarticle")
    public ResponseBean getAllArticle(){
        List<Article> list = articleService.getAllArticle();
        return new ResponseBean(200,"查询成功",list);
    }

    @RequiresRoles("admin")
    @GetMapping("delarticle")
    public ResponseBean delArticle(@RequestParam("id") int id){
        int re = articleService.delArticle(id);
        if (re != 0){
            return new ResponseBean(200,"删除成功",null);
        }else {
            return new ResponseBean(401,"删除失败",null);
        }
    }
}
